package com.onpositive.gamemaker.core;

public class BasicGameMap implements IGameMap
{
	
	protected final int width;
	protected final int height;
	protected MapCell[][] cells;

	public BasicGameMap(int width, int height)
	{
		this.width = width;
		this.height = height;
		cells = new MapCell[width][height];
	}

	@Override
	public int getWidth()
	{
		return width;
	}

	@Override
	public int getHeight()
	{
		return height;
	}

	@Override
	public MapCell getCell(int x, int y)
	{
		if (x < 0 || x >= width)
			throw new IndexOutOfBoundsException("Incorrect x postion " + x);
		if (y < 0 || y >= height)
			throw new IndexOutOfBoundsException("Incorrect y postion " + y);
		return cells[x][y];
	}
	
	/**
	 * FIXME - POTENTIALLY ERROR PRONE API - THINK ABOUT THIS
	 * @param x
	 * @param y
	 * @param cell
	 */
	public void setCell(MapCell cell)
	{
		int x = cell.getX();
		int y = cell.getY();
		if (x < 0 || x >= width)
			throw new IndexOutOfBoundsException("Incorrect x postion " + x);
		if (y < 0 || y >= height)
			throw new IndexOutOfBoundsException("Incorrect y postion " + y);
		cells[x][y] = cell;
	}
}
